package fiarredundant;

import fiarredundant.Node;
import fiarredundant.RootNode;
import fiarredundant.TreeNode;

/**
 * Created by IntelliJ IDEA.
 * <p/>
 * Date: 19/08/11
 * Time: 21:24
 */

// This is an unusual binary tree implementation, in fact, by definition it probably isn't a binary tree.
// TODO: Change name from BinaryTree to something more appropriate
public class BinaryTree {
    private RootNode root;
    private int degree;

    public BinaryTree(int degree, int rootValue) {
        this.degree = degree;
        this.root = new RootNode(degree, rootValue);
    }

    public Node getRoot() {
        return root;
    }

    public void addChild(TreeNode n, int degree) {
        TreeNode[] children = root.getChildren();
        if(children[degree] != null) children[degree] = n;
        else {
            TreeNode currentNode = root.getChild(degree);
            if(currentNode.isLeaf()) currentNode.setChild(n);


        }
    }
}



